package view.mediator.weapon.great_sword
{
	import model.item.ItemModel;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import view.component.weapon.great_sword.GreatSwordDetailView;
	import view.event.ItemEvent;
	import view.event.weapon.great_sword.GreatSwordDetailViewEvent;
	
	
	/**
	 * GreatSwordDetailView界面中介
	 * @author £iang
	 * 
	 */	
	public class GreatSwordDetailViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** GreatSwordDetailView界面 */
		[Inject]
		public var greatSwordDetailView:GreatSwordDetailView;
		/** ItemModel */
		[Inject]
		public var itemModel:ItemModel;
	
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------

		/**
		 * 注册函数 
		 * 
		 */		
		override public function onRegister():void
		{
			addContextListener( GreatSwordDetailViewEvent.SHOW_DETAIL, showDetailHandler );
			addViewListener( ItemEvent.SEARCH_ITEM, searchItemHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理请求显示大剑详细信息时派发的消息 
		 * @param event 请求显示大剑详细信息时派发的消息 
		 * 
		 */		
		protected function showDetailHandler( event:GreatSwordDetailViewEvent ):void
		{
			greatSwordDetailView.setShortData( event.weaponVo );
		}
		
		/**
		 * 处理请求查询道具时派发的消息 
		 * @param event 请求查询道具时派发的消息 
		 * 
		 */		
		protected function searchItemHandler( event:ItemEvent ):void
		{
			itemModel.curSearchItemId = event.curSearchItemId;
			dispatch( event );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeContextListener( GreatSwordDetailViewEvent.SHOW_DETAIL, showDetailHandler );
			removeViewListener( ItemEvent.SEARCH_ITEM, searchItemHandler );
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function GreatSwordDetailViewMediator()
		{
			super();
		}
	}
}